import "antd/es/result/style";
import _Result from "antd/es/result";
import "antd/es/empty/style";
import _Empty from "antd/es/empty";
import React from 'react';
import { withNativeProps } from "../utils/native-props";
import "./index.less";
import Image from "./components/Image";
import Pdf from "./components/Pdf";
import Mp4 from "./components/Mp4";
import Xlsx from "./components/Xlsx";
import Docx from "./components/Docx";
import Txt from "./components/Txt";
import { jsx as _jsx } from "react/jsx-runtime";
export default (function (props) {
  var _url$match;
  var url = props.url,
    type = props.type;
  var fileExtension = type ? type : url === null || url === void 0 ? void 0 : (_url$match = url.match(/\.[^.]+$/g)) === null || _url$match === void 0 ? void 0 : _url$match[0];
  function renderContent() {
    if (!url) {
      return /*#__PURE__*/_jsx(_Empty, {
        description: "\u8D44\u6E90\u94FE\u63A5\u4E0D\u5B58\u5728"
      });
    }
    if (!fileExtension) {
      return /*#__PURE__*/_jsx(_Result, {
        status: "error",
        title: "\u6682\u4E0D\u652F\u6301\u6B64\u7C7B\u578B\u7684\u6587\u4EF6\u9884\u89C8",
        style: {
          margin: 'auto'
        }
      });
    }
    switch (fileExtension) {
      case '.jpg':
      case '.jpeg':
      case '.png':
      case '.gif':
        return /*#__PURE__*/_jsx(Image, {
          url: url
        }, url);
      case '.pdf':
        return /*#__PURE__*/_jsx(Pdf, {
          url: url
        }, url);
      case '.xlsx':
        return /*#__PURE__*/_jsx(Xlsx, {
          url: url
        }, url);
      case '.docx':
        return /*#__PURE__*/_jsx(Docx, {
          url: url
        }, url);
      case '.txt':
        return /*#__PURE__*/_jsx(Txt, {
          url: url
        }, url);
      case '.mp4':
        return /*#__PURE__*/_jsx(Mp4, {
          url: url
        }, url);
      default:
        return /*#__PURE__*/_jsx(_Result, {
          status: "info",
          subTitle: "\u6682\u4E0D\u652F\u6301\u6B64\u7C7B\u578B\u7684\u6587\u4EF6\u9884\u89C8"
        });
    }
  }
  return withNativeProps(props, /*#__PURE__*/_jsx("div", {
    className: "ds-file-preview",
    children: renderContent()
  }));
});